package com.csu.csumall.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.csu.csumall.VO.CartVO;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.math.BigInteger;
import java.time.LocalDateTime;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderItem {
    @TableId(value = "id", type= IdType.AUTO)
    private Integer id;
    private Integer userId;
    private BigInteger orderNo;
    private Integer productId;
    private String productName;
    private String productImage;
    private Integer currentPrice;
    private Integer quantity;
    private Integer totalPrice;
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime updateTime;

    public OrderItem(CartVO cartVO, Integer userId, BigInteger orderNo) {
        this.userId = userId;
        this.orderNo = orderNo;
        this.productId = cartVO.getProductId();
        this.productName = cartVO.getProductName();
        this.productImage = cartVO.getMainImage();
        this.currentPrice = cartVO.getPrice();
        this.quantity = cartVO.getQuantity();
        this.totalPrice = cartVO.getQuantity() * cartVO.getPrice();
    }
}
